package br.com.estudosjsf.leilao.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.com.estudosjsf.leilao.domain.Marca;
import br.com.estudosjsf.leilao.domain.Modelo;

@Stateless
public class ModeloService {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	public void salvaModelo(Modelo modelo) {
		entityManager.persist(modelo);
	}
	
	@SuppressWarnings("unchecked")
	public List<Modelo> listaModelos() {
		Query query = entityManager.createQuery("select m from Modelo m order by m.nome");
		return query.getResultList();
	}
	
	@SuppressWarnings("unchecked")
	public List<Marca> listaMarcas(){
		Query query = entityManager.createQuery("select m from Marca m order by m.nome");
		return query.getResultList();
	}

}
